class ValidationError(Exception):
    code_message_dict = {
        401: "没有令牌",
        403: "没有权限",
        10001: "用户已存在",
        10002: "用户不存在",
        10003: "两次密码不一致",
        10004: "邮箱名不存在",

        20001: '参数有误',
        20002: "用户名或密码有误",
        20003: "参数不能为空",

        30001: "文件不存在",
        30002: "导入的文件中无产品",

        40001: "添加的数量不能小于已存数目",
        40002: "产品的资料未发布",
        40003: "非同一类型产品不能批量配置参数",

        50001: "文件不存在"
    }
    def __init__(self, code):
        self.code = code

    @classmethod
    def get_msg(cls, code):
        return cls.code_message_dict.get(code)


class ConnectionException(Exception):
    def __init__(self):
        super(ConnectionException, self).__init__()
        self.msg = "连接mqtt服务器失败"

    def get_msg(self):
        return self.msg


class PubMessageException(Exception):
    def __init__(self):
        super(PubMessageException, self).__init__()
        self.msg = "发布信息失败"

    def get_msg(self):
        return self.msg


class RightException(Exception):
    def __init__(self):
        super(RightException, self).__init__()
        pass


class TimeOutException(Exception):
    def __init__(self):
        super(TimeOutException, self).__init__()
        self.msg = "网关错误超时"


class RecvOutException(Exception):
    def __init__(self):
        super(RecvOutException, self).__init__()
        self.msg = "订阅网关消息超时"


class NoConnectException(Exception):
    def __init__(self):
        super(NoConnectException, self).__init__()
        self.msg = "设备不在线"


class GatewayException(Exception):
    def __init__(self, resp):
        super(GatewayException, self).__init__()
        self.msg = "".join(["网关返回异常码", resp])


class CNException(Exception):
    def __init__(self, resp):
        super(CNException, self).__init__()
        self.msg = "".join(["中国移动访问出错", resp])


class CNTokenException(Exception):
    def __init__(self, resp):
        super(CNTokenException, self).__init__()
        self.msg = "".join(["中国移动token获取出错", resp])
